﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsTheme.Helper;

namespace WindowsTheme.ThemeHelper
{
    public partial class SwitchTime : Form
    {
        public SwitchTime()
        {
            InitializeComponent();
            trackBar1.Maximum = 3600;
        }
        String LocalThemeFile = "";
        public SwitchTime(String ThemeFile)
        {
            InitializeComponent();
            trackBar1.Maximum = 3600;
            LocalThemeFile = ThemeFile;
        }

        private void button1_Click(object sender, EventArgs e)
        {
          if (GetTimer()) 
            Close();
        }

        private bool GetTimer()
        {
            int count = 0;
            try {
                count = Convert.ToInt32(textBox1.Text);
                if (count > 10)
                {
                    PrintTime(count);
                    StaticValue.Interval = count;
                    FileHelper.TextFileReplace(LocalThemeFile, @"Interval=[0-9]{1,}", "Interval="+count*1000);
                    return true;
                }
                else
                    MessageBox.Show("最短切换时间不能低于10秒！");
            }
            catch(Exception e)
            {
                PrintLog.Log(e);
                MessageBox.Show(e.Message);
            }
            return false;
         
        }

        private void PrintTime(int count)
        {
            Console.WriteLine(count*1000);
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
           textBox1.Text= trackBar1.Value.ToString();
        }
    }
}
